package com.taotao.manager.controller;

import com.taotao.common.pojo.EasyUiDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.manager.pojo.TbItem;
import com.taotao.manager.pojo.TbItemDesc;
import com.taotao.manager.service.ItemDescService;
import com.taotao.manager.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;
    @Autowired
    private ItemDescService itemDescService;
    @RequestMapping("/list")
    @ResponseBody
    public EasyUiDataGridResult getItemList(Integer page, Integer rows) {
        return itemService.getItemList(page, rows);
    }

    @RequestMapping("/save")
    @ResponseBody
    public TaotaoResult saveItem(TbItem item,String desc){
        TaotaoResult result = itemService.saveItem(item,desc);
        return result;
    }

    @RequestMapping("/update")
    @ResponseBody
    public TaotaoResult updateItem(TbItem item,String desc){
        TaotaoResult result = itemService.updateItem(item,desc);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public TaotaoResult deleteItem(String ids){
        TaotaoResult result = itemService.deleteBatchItem(ids);
        return result;
    }

    @RequestMapping("/desc/query/{id}")
    @ResponseBody
    public TaotaoResult queryItemDesc(@PathVariable Long id){

        TbItemDesc itemDesc = itemDescService.getItemDesc(id);
        return TaotaoResult.ok(itemDesc);
    }
}
